<?php
/**
 * @package GoogleCheckout
 * @author Byrne Reese <byrne@majordojo.com>
 * @copyright 2006-2008, Byrne Reese.
 */

require_once("MySQLGoogleCheckoutServer.php");
require_once("Discount.php");

/**
 *   TODO - This implementation for discounts is weak at best. 
 *     1) if a transaction fails, then there is no rollback for
 *        unredeeming a discount code
 *     2) if two people try to redeem a code at the same time, it is
 *        possible for two people to redeem the same discount, or to
 *        exceed the limit of allowable discounts
 *
 * @package GoogleCheckout
 */
class ExampleGoogleCheckoutServer extends MySQLGoogleCheckoutServer {
  function doNewOrderNotification($request,$response) {
    $code = $request->shoppingCart->privateData['discountCode'];
    if ($code) {
      $this->log($request->serialNumber(),$request->orderNumber(),
		 "Received discount code: " . $code );
      $discount = Discount::findByCode($code);
      $discount->redeem();
    }
    parent::doNewOrderNotification($request,$response);
  }
  function doOrderStateChangeNotification($request,$response) {
    parent::doOrderStateChangeNotification($request,$response);
    if ($request->financialState() == "CHARGED") {
    }
  }
}
?>